namespace Guia.Elements
{
    using System.Windows.Automation;
    using Guia.Core;
    using Guia.Elements.PatternServants;
    using Guia.Locator;

    /// <summary>
    /// This class represents a ToggleButton
    /// </summary>
    public class ToggleButton : UiElement, IToggle
    {
        /// <summary>
        /// Represents a helper-servant for the Toggle-pattern.
        /// </summary>
        private readonly IToggle toggleServant;

        /// <summary>
        /// Initializes a new instance of the <see cref="ToggleButton"/> class.
        /// </summary>
        /// <param name="automationElement">
        /// The automation element.
        /// </param>
        public ToggleButton(AutomationElement automationElement) : base(automationElement)
        {
            this.toggleServant = new ToggleImpl(this);
        }

        /// <summary>
        /// Gets the default-condition to find a control by its type.
        /// </summary>
        public static SearchCondition ControlTypeCondition
        {
            get { return SearchCondition.ByControlType(ControlType.Button); }
        }

        /// <summary>
        /// Gets a value indicating whether the state is off or not.
        /// </summary>
        public bool IsOff
        {
            get
            {
                return this.toggleServant.IsOff;
            }
        }

        /// <summary>
        /// Gets a value indicating whether the state is on or not.
        /// </summary>
        public bool IsOn
        {
            get
            {
                return this.toggleServant.IsOn;
            }
        }

        /// <summary>
        /// Gets a value indicating whether the state is indeterminate or not.
        /// </summary>
        public bool IsIndeterminate
        {
            get
            {
                return this.toggleServant.IsIndeterminate;
            }
        }

        /// <summary>
        /// Toggles the ToggleButton.
        /// </summary>
        /// <exception cref="OperationNotSupportedException">
        /// </exception>
        public void Toggle()
        {
            this.toggleServant.Toggle();
        }
    }
}